<?php
namespace Message\Controller;

use Common\Controller\AdminbaseController;

class MessageAdminController extends AdminbaseController {

	public function _initialize() {
		parent::_initialize();
	}
    public function index()
    {
    	$message=M("message","cmf_");
    	
        /*$where=array();
        $request=I('request.');
        
        if(!empty($request['uid'])){
            $where['id']=intval($request['uid']);
        }
        
        if(!empty($request['keyword'])){
            $keyword=$request['keyword'];
            $keyword_complex=array();
            $keyword_complex['user_login']  = array('like', "%$keyword%");
            $keyword_complex['user_nicename']  = array('like',"%$keyword%");
            $keyword_complex['user_email']  = array('like',"%$keyword%");
            $keyword_complex['_logic'] = 'or';
            $where['_complex'] = $keyword_complex;
        }
        */
    	$count=$message->where("status=2")->count();
    	$page = $this->page($count, 20);
    	
    	$list = $message
        ->alias("a")
        ->join("cmf_posts b on a.post_id=b.id")
        ->field("a.user_id,a.content,a.create_time,a.status,b.post_title")
    	->order("create_time DESC")
    	->limit($page->firstRow . ',' . $page->listRows)
    	->select();
    	var_dump($list);
    	$this->assign('list', $list);
    	$this->assign("page", $page->show('Admin'));

        $this->display();
    }

    public function agree(){
    	$id= I('get.id',0,'intval');
    	if ($id) {
    		$result = M("message","cmf_")->where(array("id"=>$id))->setField('status',0);
    		if ($result) {
    			$this->success("留言通过！", U("MessageAdmin/index"));
    		} else {
    			$this->error('留言通过失败,留言不存在,或者是管理员！');
    		}
    	} else {
    		$this->error('数据传入失败！');
    	}
    }

    public function disagree(){
    	$id= I('get.id',0,'intval');
    	if ($id) {
    		$result = M("message","cmf_")->where(array("id"=>$id))>setField('status',1);
    		if ($result) {
    			$this->success("留言不通过！", U("MessageAdmin/index"));
    		} else {
    			$this->error('留言不通过失败,留言不存在,或者是管理员！');
    		}
    	} else {
    		$this->error('数据传入失败！');
    	}
    }
}